<html>
<head>
<script>
	chrome.browserAction.onClicked.addListener(function(tab) 
	{
		if(localStorage["get_selector_path_" + tab.id] == 1)
		{
			chrome.tabs.executeScript(tab.id,{file:"jquery/jquery-1.7.min.js"});
			chrome.tabs.executeScript(tab.id,{file:"init_selector.js"});
			localStorage["get_selector_path_" + tab.id] = 0;
		}
		chrome.tabs.executeScript(tab.id,{file:"selector.js"});
	});
	
	chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) 
    {
        if ( changeInfo.status == "complete" ) 
        {
            localStorage["get_selector_path_" + tabId] = 1;
        }
    });
	
	chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) 
	{
		if(removeInfo.isWindowClosing == true)
			localStorage.clear();
		else
			localStorage.removeItem("get_selector_path_" + tabId);
	});
</script>
</head>
</html>
